package com.axend.aerosense.user.adapter;

import android.view.View;

import com.axend.aerosense.user.entity.LoginDevInfoBean;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder;
import com.axend.aerosense.base.impl.IOperation;
import com.axend.aerosense.base.utils.EquipmentUtil;
import com.axend.aerosense.user.R;
import com.axend.aerosense.user.databinding.UserOnlineDevItemBinding;

import org.jetbrains.annotations.NotNull;


public class LoginDevListAdapter extends BaseQuickAdapter<LoginDevInfoBean, BaseDataBindingHolder<UserOnlineDevItemBinding>> {
    private UserOnlineDevItemBinding dataBinding;
    private IOperation<LoginDevInfoBean> clickListence;
    public LoginDevListAdapter() {
        super(R.layout.user_online_dev_item);
    }

    @Override
    protected void convert(@NotNull BaseDataBindingHolder<UserOnlineDevItemBinding> baseViewHolder, LoginDevInfoBean loginDevInfoBean) {
        if (loginDevInfoBean == null) {
            return;
        }

        // 获取 Binding
        dataBinding = (UserOnlineDevItemBinding) baseViewHolder.getDataBinding();
        if (dataBinding != null) {
            if(EquipmentUtil.getUUID().equals(loginDevInfoBean.userAppUuid)){
                dataBinding.userPhoneCurrent.setVisibility(View.VISIBLE);
                dataBinding.devDelet.setVisibility(View.GONE);
            }else{
                dataBinding.userPhoneCurrent.setVisibility(View.GONE);
            }

            dataBinding.setData(loginDevInfoBean);
            // 设置数据
            dataBinding.devDelet.setOnClickListener(v->{
                if(null != clickListence){
                    clickListence.complete(loginDevInfoBean);
                }
            });
        }
    }

    public void setOnDeleteItemClickListence(IOperation<LoginDevInfoBean> clickListence){
        this.clickListence = clickListence;
    }


}
